import request from '@/utils/request'

// api地址
const api = {
    index: 'book/index',
    detail: 'book/detail',
    clearKeys: 'media',
    checkInviteCode: 'book/invite/check',
    bind: 'book/invite/bind',
    auth: 'book/auth',
    nodes: 'book/nodes',
    oldDetail: 'book/detailOld',
    authDetail: 'book/needAuth'
}

// 书本详情
export const info = (id) => {
    return request.get(api.index + '/' + id)
}

// 书页详情
export const detail = (id, isHls) => {
    return request.get(api.detail + '/' + id + '?hls=' + (isHls ? 1 : 0))
}

// 获取节点
export const nodes = (id, isHls) => {
    return request.get(api.nodes + '/' + id + '?hls=' + (isHls ? 1 : 0))
}

// 校验邀请码
export const checkInviteCode = (id) => {
    return request.get(api.checkInviteCode + '/' + id, null, {
        isPrompt: false
    })
}
//绑定
export const bind = (data) => {
    return request.post(api.bind, data)
}
//授权
export const auth = (data) => {
    return request.post(api.auth, data)
}

export const clearKeys = (data) => {
    return request.sendBeacon(api.clearKeys, data, { otherApi: true })
}

export const oldDetail = (id, isHls) => {
    return request.get(api.oldDetail + '/' + id + '?hls=' + (isHls ? 1 : 0))
}

export const authDetail = (id, type) => {
    return request.get(api.authDetail, { id, type })
}
